<template>
  <div>
    <h1>todolist</h1>
    <input type="text" v-model="msg" @keyup.enter="handleEnter" />
    <div class="box">
      <p v-for="item of arr" :key="item">
        {{ item }}
        <button @click="handleDelete(item)">删除</button>
      </p>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from "vue";
export default {
  setup() {
    const state = reactive({
      msg: "",
      arr: [],
      handleEnter() {
        if (!this.arr.includes(this.msg)) {
          this.arr.push(this.msg);
        }
        this.msg = "";
      },
      handleDelete(item) {
        this.arr.splice(this.arr.indexOf(item), 1);
      },
    });
    const refState = toRefs(state);
    return {
      ...refState,
    };
  },
};
</script>

<style scoped>
p {
  line-height: 24px;
}
</style>